package com.xinqi.modules.file.textimg.service.impl;

import com.xinqi.modules.file.textimg.config.BaseAvatarConfig;
import com.xinqi.modules.file.textimg.service.TextImageService;
import com.xinqi.modules.file.textimg.util.TextUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class TextImageServiceImpl implements TextImageService {

    private BaseAvatarConfig baseAvatarConfig;

    @Override
    public String creatTowTextAvatar(String text) {
        String tranText = TextUtil.tranText(text, 2);
        String base64Text = TextUtil.urlSafeBase64Encode(tranText);
        return createUrl(base64Text);
    }

    private String createUrl(String base64Url) {
        String url = baseAvatarConfig.getBaseAvatarUrl() + "," + baseAvatarConfig.getAvatarType()
            + "," + baseAvatarConfig.getAvatarSize() + "," + baseAvatarConfig.getAvatarColor()
            + "," + baseAvatarConfig.getAvatarCenter() + "," + baseAvatarConfig.getAvatarText()
            + base64Url;
        return url;
    }
}
